﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartLib.Cfg;
using System.Configuration;
using System.Data.Common;
using System.Linq.Expressions;

namespace SmartLib.Dal
{
    /// <summary>
    /// DBProvider
    /// </summary>
    public static class DBProvider
    {
        private static DBProviderConfigurationSection _dbProviderSection;
        private static Dictionary<string, DBFactory> _factoriesCache;

        static DBProvider()
        {
            _dbProviderSection = (DBProviderConfigurationSection)ConfigurationManager.GetSection("DBProvider");
            _factoriesCache = new Dictionary<string, DBFactory>();
            for (var i = 0; i < _dbProviderSection.DBFactories.Count; i++)
            {
                DBFactoryElement element = _dbProviderSection.DBFactories.GetDBFactoryElement(i);
                _factoriesCache.Add(element.Name, new DBFactory(element));
            }
        }

        /// <summary>
        /// 通过配制名称获取DBFactory
        /// </summary>
        /// <param name="name">配置名称</param>
        /// <returns></returns>
        public static DBFactory GetDBFactory(string name)
        {
            if (_factoriesCache.ContainsKey(name)) return _factoriesCache[name];
            return null;
        }

       
    }
}
